package com.yyfax.pay.order.model.vo;

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.io.xml.QNameMap;
import com.thoughtworks.xstream.io.xml.StaxDriver;
import com.thoughtworks.xstream.io.xml.StaxWriter;

import java.io.StringWriter;

@XStreamAlias("REQUEST")
public class ProtocolPayVO {

    @XStreamAlias("VERSION")
    private String version;

    @XStreamAlias("USERIP")
    private String userIp;

    @XStreamAlias("MCHNTCD")
    private String merchantCode;

    @XStreamAlias("TYPE")
    private String type;

    @XStreamAlias("MCHNTORDERID")
    private String orderId;

    @XStreamAlias("USERID")
    private String userId;

    @XStreamAlias("AMT")
    private Long amt;

    @XStreamAlias("PROTOCOLNO")
    private String protocolCode;

    @XStreamAlias("NEEDSENDMSG")
    private Integer needMessage;

    @XStreamAlias("BACKURL")
    private String notifyUrl;

    @XStreamAlias("SIGNTP")
    private String signType;

    @XStreamAlias("SIGN")
    private String sign;

    public String getVersion() {
        return version;
    }

    public void setVersion(String version) {
        this.version = version;
    }

    public String getUserIp() {
        return userIp;
    }

    public void setUserIp(String userIp) {
        this.userIp = userIp;
    }

    public String getMerchantCode() {
        return merchantCode;
    }

    public void setMerchantCode(String merchantCode) {
        this.merchantCode = merchantCode;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getOrderId() {
        return orderId;
    }

    public void setOrderId(String orderId) {
        this.orderId = orderId;
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public Long getAmt() {
        return amt;
    }

    public void setAmt(Long amt) {
        this.amt = amt;
    }

    public String getProtocolCode() {
        return protocolCode;
    }

    public void setProtocolCode(String protocolCode) {
        this.protocolCode = protocolCode;
    }

    public Integer getNeedMessage() {
        return needMessage;
    }

    public void setNeedMessage(Integer needMessage) {
        this.needMessage = needMessage;
    }

    public String getNotifyUrl() {
        return notifyUrl;
    }

    public void setNotifyUrl(String notifyUrl) {
        this.notifyUrl = notifyUrl;
    }

    public String getSignType() {
        return signType;
    }

    public void setSignType(String signType) {
        this.signType = signType;
    }

    public String getSign() {
        return sign;
    }

    public void setSign(String sign) {
        this.sign = sign;
    }

    public String toXml() {
        QNameMap qmap = new QNameMap();
        qmap.setDefaultPrefix("");
        StaxDriver staxDriver = new StaxDriver(qmap);
        XStream xstream = new XStream(staxDriver);
        xstream.autodetectAnnotations(true);
        xstream.ignoreUnknownElements();
        xstream.alias("REQUEST", ProtocolPayVO.class);
        try {
            StringWriter strWriter = new StringWriter();
            StaxWriter sw = new StaxWriter(staxDriver.getQnameMap(), staxDriver.getOutputFactory().createXMLStreamWriter(strWriter), false, true);
            xstream.marshal(this, sw);
            sw.close();
            return "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>"+ strWriter.toString();
            //return strWriter.toString();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
